<?php
	function getlevel($level){
		switch($level){
			case 1:
			$re="一等奖";break;
			case 2:
			$re="二等奖";break;
			case 3:
			$re="三等奖";break;
			case 4:
			$re="鼓励奖";break;
			case 5:
			$re="<span class=\"auxiliary-text\">不显示等级</span>";break;
			case 6:
			$re="<span class=\"auxiliary-text\">隐含奖品</span>";break;
			default:$re = "";break;
		}
		return $re;
	}
	function out($sec){
		$d = floor($sec / 86400);
		$tmp = $sec % 86400;
		$h = floor($tmp / 3600);
		$tmp %= 3600;
		$m = floor($tmp /60);
		$s = $tmp % 60;
		$c["t"]=($d?$d."天":"").($h?$h."小时":'').($m?$m."分":"").$s."秒";
		if($d>=1){
			$c["s"]=5;
		}else{
			if($h>=12){
				$c["s"]=4;
			}else{
				if($h>1){
					$c["s"]=3;
				}else{
					if($h>0){
						$c["s"]=2;
					}else{
						$c["s"]=1;
					}
				}
			}
		}
		return $c;
	}
	function ismobile(){
		if(!session('ISMOBILE')){
			Vendor('MobileDetect.Mobile_Detect');
			$detect = new Mobile_Detect;
			$ism = $detect->isMobile();
			session('ISMOBILE',$ism);
			return $ism;
		}else{
			return session('ISMOBILE');
		}
	}
//与原生不符：utf8编码使用单另的函数： urlencode_utf8，在任何情况下urlencode都输出gb2312编码：
	function GetWeek($ctp){
		switch($ctp){
				case "eggs" :$week["name"] = "一";$week["num"]=1;break;
				case "wheels" :$week["name"] = "二";$week["num"]=2;break;
				case "dices" :$week["name"] = "三";$week["num"]=3;break;
				case "fruit" :$week["name"] = "四";$week["num"]=4;break;
				case "mice" :$week["name"] = "五";$week["num"]=5;break;
				case "scratchcards" :$week["name"] = "六";$week["num"]=6;break;
				case "comment" :$week["name"] = "日";$week["num"]=7;break;
			}
		return $week;
	}
	function GetTimeInfo($time){
		$timein = $time-time();
		$info="";
		if($timein>0){$info="后";}else{$info="前";}
		$timein = abs($timein);
		if(($timein)<60){$timeinfo=($timein)."秒".$info;}
		elseif(($timein)>60&&($timein)<3600){$timeinfo=(int)(($timein)/60)."分钟".$info;}
		elseif(($timein)>3600&&($timein)<86400){$timeinfo=(int)(($timein)/3600)."小时".$info;}
		elseif(($timein)>86400&&(($timein)/86400)<14){$timeinfo=(int)(($timein)/86400)."天".$info;}
		elseif((($timein)/86400)<365){$timeinfo = date("n月j日",$time);}
		else{$timeinfo = date("Y年n月j日",$time);}
		return $timeinfo;
	}	
	function LeftTime($time){
		$timein = $time-time();
		if($timein>0){
			$info="";
			if(($timein)<60){$timeinfo=($timein)."秒".$info;}
			elseif(($timein)>60&&($timein)<3600){$timeinfo=(int)(($timein)/60)."分钟".$info;}
			elseif(($timein)>3600&&($timein)<86400){$timeinfo=(int)(($timein)/3600)."小时".$info;}
			else{$timeinfo=(int)(($timein)/86400)."天".$info;}
		}else{
			$timeinfo = "0秒";
		}
		return $timeinfo;
	}
	function LetterAsKey($data){
		$index = str_split("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",1); 
		$i=0;
		foreach($data as $k=>$d){
			$reda[$index[$i]]=$d;
			$i++;
		}
		return $reda;
	}
	
	function GetCreditString($lev){
		if ($lev<10){
		$lev='http://a.tbcdn.cn/sys/common/icon/rank/b_1_1.gif';
		}elseif($lev>10&&$lev<=40){
		$lev='http://a.tbcdn.cn/sys/common/icon/rank/b_1_2.gif';
		}elseif($lev>40&&$lev<=90){
		$lev='http://a.tbcdn.cn/sys/common/icon/rank/b_1_3.gif';
		}elseif($lev>90&&$lev<=150){
		$lev='http://a.tbcdn.cn/sys/common/icon/rank/b_1_4.gif';
		}elseif($lev>150&&$lev<=250){
		$lev='http://a.tbcdn.cn/sys/common/icon/rank/b_1_5.gif';
		}elseif($lev>250&&$lev<=500){
		$lev='http://pics.taobaocdn.com/newrank/s_blue_1.gif';
		}elseif($lev>500&&$lev<=1000){
		$lev='http://pics.taobaocdn.com/newrank/s_blue_2.gif';
		}elseif($lev>1000&&$lev<=2000){
		$lev='http://pics.taobaocdn.com/newrank/s_blue_3.gif';
		}elseif($lev>2000&&$lev<=5000){
		$lev='http://pics.taobaocdn.com/newrank/s_blue_4.gif';
		}elseif($lev>5000&&$lev<=10000){
		$lev='http://pics.taobaocdn.com/newrank/s_blue_5.gif';
		}elseif($lev>10000&&$lev<=20000){
		$lev='http://pics.taobaocdn.com/newrank/s_cap_1.gif';
		}elseif($lev>20000&&$lev<=50000){
		$lev='http://pics.taobaocdn.com/newrank/s_cap_2.gif';
		}elseif($lev>50000&&$lev<=100000){
		$lev='http://pics.taobaocdn.com/newrank/s_cap_3.gif';
		}elseif($lev>100000&&$lev<=200000){
		$lev='http://pics.taobaocdn.com/newrank/s_cap_4.gif';
		}elseif($lev>200000&&$lev<=500000){
		$lev='http://pics.taobaocdn.com/newrank/s_cap_5.gif';
		}elseif($lev>500000&&$lev<=1000000){
		$lev='http://pics.taobaocdn.com/newrank/s_crown_1.gif';
		}elseif($lev>1000000&&$lev<=2000000){
		$lev='http://pics.taobaocdn.com/newrank/s_crown_2.gif';
		}elseif($lev>2000000&&$lev<=5000000){
		$lev='http://pics.taobaocdn.com/newrank/s_crown_3.gif';
		}elseif($lev>5000000&&$lev<=10000000){
		$lev='http://pics.taobaocdn.com/newrank/s_crown_4.gif';
		}elseif($lev>10000000){
		$lev='http://pics.taobaocdn.com/newrank/s_crown_5.gif';
		}
	return $lev;
	}
	function GetBuyerCreditString($lev){
		if ($lev>4&&$lev<=10){
		$lev='http://pics.taobaocdn.com/newrank/b_red_1.gif';
		}elseif($lev>10&&$lev<=40){
		$lev='http://pics.taobaocdn.com/newrank/b_red_2.gif';
		}elseif($lev>40&&$lev<=90){
		$lev='http://pics.taobaocdn.com/newrank/b_red_3.gif';
		}elseif($lev>90&&$lev<=150){
		$lev='http://pics.taobaocdn.com/newrank/b_red_4.gif';
		}elseif($lev>150&&$lev<=250){
		$lev='http://pics.taobaocdn.com/newrank/b_red_5.gif';
		}elseif($lev>250&&$lev<=500){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_1.gif';
		}elseif($lev>500&&$lev<=1000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_2.gif';
		}elseif($lev>1000&&$lev<=2000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_3.gif';
		}elseif($lev>2000&&$lev<=5000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_4.gif';
		}elseif($lev>5000&&$lev<=10000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_5.gif';
		}elseif($lev>10000&&$lev<=20000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_1.gif';
		}elseif($lev>20000&&$lev<=50000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_2.gif';
		}elseif($lev>50000&&$lev<=100000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_3.gif';
		}elseif($lev>100000&&$lev<=200000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_4.gif';
		}elseif($lev>200000&&$lev<=500000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_5.gif';
		}elseif($lev>500000&&$lev<=1000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_1.gif';
		}elseif($lev>1000000&&$lev<=2000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_2.gif';
		}elseif($lev>2000000&&$lev<=5000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_3.gif';
		}elseif($lev>5000000&&$lev<=10000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_4.gif';
		}elseif($lev>10000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_5.gif';
		}
	return $lev;
	}
	function to_utf8( $string ) { 
		$encoding = mb_detect_encoding($string, 'UTF-8,GBK,GB2312');echo $encoding;
		if (mb_detect_encoding($string, 'UTF-8') === 'UTF-8') { 
			return $string; 
		} else { 
			return iconv( $encoding, 'UTF-8', $string); 
		} 
	} 
	// function urldecode_utf8($string){
		// if (function_exists(urldecode)){
			// return urldecode($string);
		// }else{
			// echo 'urldecode_utf8 未定义！请定义该函数';
		// }
	// }
	function substr_cut($str_cut,$length)
	{
		if (strlen($str_cut) > $length)
		{
			for($i=0; $i < $length; $i++)
			if (ord($str_cut[$i]) > 128)    $i++;
			$str_cut = substr($str_cut,0,$i)."...";
		}
		return $str_cut;
	}